<template>
	<div id="password">
		<div id="header">
			<img @click="$router.go(-1)" src="../../static/img/return.png"/>
			<p>{{type == 1?'修改登录密码':'修改支付密码'}}</p>
		</div>
		<input type="password" placeholder="请输入当前登录密码" v-model="password" />
		<input type="password" placeholder="请输入新的密码" v-model="newPassword" />
		<input type="password" placeholder="请重复新的密码" v-model="again"/>
		<input type="button" @click="update" value="确定" />
	</div>
</template>

<script>
export default{
	name: 'password',
	data:function(){
		return{
			type: 1,//1 登录密码  2 支付密码
			password: '',
			newPassword: '',
			again: ''
		}
	},
	methods: {
		update: function(){
			var _this = this;
			
			if(!_this.password){
				_this.$alert("请输入原密码");
				return;
			}
			if(!_this.newPassword){
				_this.$alert("请输入新密码");
				return;
			}
			if(!_this.again){
				_this.$alert("请再次输入新密码");
				return;
			}
			if(_this.again != _this.newPassword){
				_this.$alert("两次输入的密码不一致");
				return;
			}
			
			let postData = _this.$qs.stringify({
				oldPwd: _this.password,
				newPwd: _this.newPassword,
				rePwd: _this.again
			});
			var url;
			if(_this.type == 2){
				url = "/user/info/updatePayPwd";
			}else if(_this.type == 1){
				url = "/user/autho/updateLoginPwd";
			}
			_this.$axios.post(url, postData).then(function(res){
				var data = res.data;
				if(data.message == "succ"){
					_this.$alert("修改密码成功");
					if(_this.type == 1){
						_this.$router.replace('/login');
					}else{
						_this.$router.go(-1);
					}
				}else{
					_this.$alert(data.result);
				}
			}).catch(function(err){
				console.log(err);
			});
		}
	},
	created:function(){
		if(this.$route.query.type < 1 || this.$route.query.type > 2){
			this.$router.go(-1);
		}
		this.type = this.$route.query.type;
	}
}
</script>

<style scoped>
/* ========== */
/* = Header = */
/* ========== */
#header{
	width: 100%;
	background-color: #fff;
	position: fixed;
	top: 0;
	left: 0;
	height: 4rem;
	display: flex;
	align-items: center;
	justify-content: center;
	border-bottom: 1px solid #EEEEEE;
	font-size: 1.6rem;
	color: #4F4F4F;
	box-sizing: border-box;
	z-index: 10;
}
#header img{
	height: 2rem;
	display: block;
	position: absolute;
	top: 1rem;
	left: 2rem;
}
#password{
	height: 100%;
	padding-top: 5rem;
	box-sizing: border-box;
	background-color: #fff;
}
input[type='password']{
	width: 90%;
	height: 3.2rem;
	font-size: 1.2rem;
	border: 1px solid #EEEEEE;
	padding-left: 1rem;
	box-sizing: border-box;
	display: block;
	margin: 0 auto;
	margin-bottom: 1rem;
}
input[type='button']{
	width: 90%;
	height: 3.2rem;
	font-size: 1.2rem;
	border: none;
	background-color: #FF6565;
	box-sizing: border-box;
	display: block;
	margin: 0 auto;
	color: #FFFFFF;
}
</style>